
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php 
if(!isset($_SESSION['UserName']))
{
//	include "formdangnhap.php"; 
echo "<script language='javascript'>alert(' Bạn phải đăng nhập !'); location.href='../index.php';</script>";
}
?>
<table width="537" border="1" align="center" bgcolor="#FFC">
  <tr>
    <td colspan="8" align="center">Danh Sách Sản Phẩm<br /><a href="index.php?ACT=themsp">Thêm</a></td>
  </tr>
  <tr align="center">
    <td>Mã Sp</td>
    <td>Tên Máy</td>
    <td>Ngày Cập Nhật</td>
    <td>Giá</td>
    <td>Hình</td>
    <td>idLM</td>
    <td>Sửa</td>
    <td>Xóa</td>
  </tr>
  <?php
  
  	require_once("connect/dbcon.php");
 


 $sodong=5;
  $nhom=5;			// so trang trong 1 nhom trang
  
  if(!isset($_GET["tst"])) {				// kiem tra da co tong so trang chua
  $kq=mysql_query("select * from may",$link);
  $tongsotrang=ceil(mysql_num_rows($kq)/$sodong);
  $tongsonhom=ceil($tongsotrang/$nhom);
  }
  else
  {
  $tongsotrang=intval($_GET["tst"]);
   $tongsonhom=ceil($tongsotrang/$nhom);
  }
  
  
  
  if (!isset($_GET["p"]))      // neu chua co tham so p
  { 
      if (!isset($_GET["n"]))		// neu chua co tham so n
	  {$p=1; $n=1; }			// nhom hien hanh
	  else
	  {$n=intval($_GET["n"]);
	   $p=$n*$nhom-$nhom+1;  }			// tinh trang dau tien cua nhom n
  
  }
  else
  {
  	$p=intval($_GET["p"]);
	$n=ceil($p/$nhom);
  }
  
  $x=($p-1)*$sodong;

	$s="select * from may order by idMay DESC limit $x,$sodong";
	$kq=mysql_query($s,$link);
	while($d=mysql_fetch_array($kq))
		{
  ?>
  <tr align="center">
    <td width="100"><?php echo $d["idMay"];?></td>
    <td width="160"><?php echo $d["TenMay"];?></td>
    <td width="200"><?php echo $d["Ngay"];?></td>
    <td width="100"><?php echo $d["Gia"];?></td>
    <td width="100"><img width="100" height="100" src="images/product/<?php echo $d["UrlHinh"];?>" /></td>
    <td width="100"><?php echo $d["idLM"];?></td>
    <td width="100"><a href="index.php?ACT=suasp&idMay=<?php echo $d["idMay"];?>">Sửa</a></td>
    <td width="100"><a href="index.php?ACT=xoasp&idMay=<?php echo $d["idMay"];?>">Xóa</a></td>
  </tr>
  <?php }?>
</table>
<p align="center">
<?php if ($n>1) {
	$n1=$n-1;
?>
<a href="index.php?ACT=sp&n=<?php echo $n1; ?>&tst=<?php echo $tongsotrang; ?>"><<</a>&nbsp;

<?php } ?>	
<?php
$dau=($n-1)*$nhom+1;			// $dau : trang dau tien cua nhom n.
if ($n<$tongsonhom)				// neu chua phai la nhom cuoi .
{$cuoi=$dau+$nhom-1;
}
else
{$cuoi=$tongsotrang;}			// nguoc lai thi chon luon tongsotrang
for($i=$dau;$i<=$cuoi;$i++) 		
{ if ($i==$p)
   { echo $i."&nbsp;";
   }
   else
   {
 ?>
 <a href="index.php?ACT=sp&p=<?php echo $i; ?>&tst=<?php echo $tongsotrang; ?>"><?php echo $i; ?></a>
<?php
   }
}
?>   
<?php if ($n<$tongsonhom) {
	$n2=$n+1;
?>
<a href="index.php?ACT=sp&n=<?php echo $n2; ?>&tst=<?php echo $tongsotrang; ?>">>></a>&nbsp;
<?php } ?>
</p>
</body>
</html>
